package com.hx.petsever.controller;

import com.hx.petsever.config.Result;
import com.hx.petsever.entity.Vip;
import com.hx.petsever.mapper.VipMapper;
import com.hx.petsever.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/vip")
public class VipController {

    @Autowired
    VipService vipService;

    @Autowired
    VipMapper vipMapper;

    @RequestMapping("/toRegist")
    public Result toRegist(Vip vip)
    {
        Result<Object> objectResult = new Result<>();
        HashMap<String,Object> hashMap = vipService.toVip(vip.getUserid(), vip.getVip(), vip.getAccount());
        objectResult.setData(hashMap.get("data"));
        objectResult.success(hashMap.get("msg").toString());
        return objectResult;
    }

    @RequestMapping("/haveVip")
    public Result haveVip(String userid) {
        Vip vip1 = vipMapper.havaVip(userid);
        Result result = new Result();
        if(vip1 != null)
        {
            result.setData(vip1);
            result.success("已是会员！");
        }else{
            result.fail("成为会员");
        }
        return result;
    }
}
